package com.zjgsu.demo.Repository;

import com.zjgsu.demo.nodeEntity.Trouble;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;

public interface TroubleRepository extends Neo4jRepository<Trouble, Long> {
    Trouble findTroubleByName(@Param("name") String name);

    @Query("MATCH (m:device) WHERE m.title = {title} DELETE m RETURN m")
    Trouble deleteDeviceByName(@Param("name") String name);

    @Query("MATCH (m:trouble),(n:device) WHERE m.name ={troublename} AND n.title = {deivcetitle}  CREATE (m)-[r:拥有]->(n) RETURN r")
    void troubleAddDevice(@Param("troublename") String troublename, @Param("deivcetitle") String deivcetitle);

    @Query("MATCH (n:trouble),(m:device) WHERE m.name ={deivcetitle} AND n.title = {troublename}  CREATE (m)-[r:拥有]->(n) RETURN r")
    void deviceAddTrouble(@Param("troublename") String troublename, @Param("deivcetitle") String deivcetitle);

    @Query("MATCH (m:trouble)-[r:拥有]-(n:device) WHERE m.name = {troublename} AND n.title = {deviceTitle} DELETE r ")
    void  troubleDeleteDevice(@Param("troublename") String troublename,@Param("deivceTitle") String deviceTitle);
}
